package cn.stylefeng.guns.modular.tool.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.basic.service.BasicWarehouseService;
import cn.stylefeng.guns.modular.tool.entity.ToolBtnShift;
import cn.stylefeng.guns.modular.tool.model.params.ToolBtnShiftParam;
import cn.stylefeng.guns.modular.tool.service.ToolBtnShiftService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 批量移库明细控制器
 *
 * @author zhucx
 * @Date 2023-04-08 10:42:40
 */
@Controller
@RequestMapping("/toolBtnShift")
public class ToolBtnShiftController extends BaseController {

    private String PREFIX = "/tool/toolBtnShift";

    @Autowired
    private ToolBtnShiftService toolBtnShiftService;

    @Autowired
    private BasicWarehouseService basicWarehouseService;

    @Autowired
    private UserService userService;

    /**
     * 跳转到主页面
     *
     * @author zhucx
     * @Date 2023-04-08
     */
    @RequestMapping("")
    public String index(Model model) {
    	User user = userService.getcurrentUser();
    	Long deptId = user.getDeptId();
    	Long deliverId = user.getDeliverId();
        model.addAttribute("wlist", basicWarehouseService.findAvailableList(deptId,deliverId,user.getOperateId()));
        return PREFIX + "/toolBtnShift.html";
    }

    /**
     * 新增页面
     *
     * @author zhucx
     * @Date 2023-04-08
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/toolBtnShift_add.html";
    }

    /**
     * 编辑页面
     *
     * @author zhucx
     * @Date 2023-04-08
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/toolBtnShift_edit.html";
    }

    /**
     * 新增接口
     *
     * @author zhucx
     * @Date 2023-04-08
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ToolBtnShiftParam toolBtnShiftParam) {
        this.toolBtnShiftService.add(toolBtnShiftParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author zhucx
     * @Date 2023-04-08
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ToolBtnShiftParam toolBtnShiftParam) {
        this.toolBtnShiftService.update(toolBtnShiftParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author zhucx
     * @Date 2023-04-08
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ToolBtnShiftParam toolBtnShiftParam) {
        this.toolBtnShiftService.delete(toolBtnShiftParam);
        return ResponseData.success();
    }

    /**
     * 批量删除接口
     */
    @RequestMapping("/btnRevoke")
    @ResponseBody
    public ResponseData btnRevoke(Integer[] ids) {
    	for (Integer id : ids) {
    		ToolBtnShiftParam toolBtnShiftParam = new ToolBtnShiftParam();
    		toolBtnShiftParam.setId(id);
			this.toolBtnShiftService.delete(toolBtnShiftParam);
		}
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author zhucx
     * @Date 2023-04-08
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ToolBtnShiftParam toolBtnShiftParam) {
        ToolBtnShift detail = this.toolBtnShiftService.getById(toolBtnShiftParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author zhucx
     * @Date 2023-04-08
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(ToolBtnShiftParam toolBtnShiftParam,String condition ,String startTime,String endTime) {
    	User user = userService.getcurrentUser();
    	toolBtnShiftParam.setDeptId(user.getDeptId());
    	if (ToolUtil.isNotEmpty(startTime) && ToolUtil.isNotEmpty(endTime)) {
    		toolBtnShiftParam.setV1("'"+startTime+"' and '"+endTime+"'");
		}
        return this.toolBtnShiftService.findPageBySpec(toolBtnShiftParam,condition,user.getOperateId());
    }

}


